// Created by Administrator on 2017/12/9.
//

#include <jni.h>
#include <android/native_window_jni.h>
#include "log.h"
#include "MyPlayer.h"

ANativeWindow *window;

MyPlayer *player;
JavaVM *gVm;

jint JNI_OnLoad(JavaVM *vm, void *reserved) {
    gVm = vm;
    return JNI_VERSION_1_4;
}

void listener(int what, int arg1, int arg2) {

}

extern "C"
JNIEXPORT void JNICALL
Java_com_example_myplayerlib_player_MyPlayer__1setDataSource(JNIEnv *env, jobject instance,
                                                             jstring _path) {
    player = new MyPlayer();
    char input_name[500] = {0};
    sprintf(input_name, "%s", env->GetStringUTFChars(_path, NULL));
    player->set_data_source(input_name);
    player->set_event_listener(listener);
}

extern "C"
JNIEXPORT void JNICALL
Java_com_example_myplayerlib_player_MyPlayer__1setSurface(JNIEnv *env, jobject instance,
                                                          jobject surface) {
    window = ANativeWindow_fromSurface(env, surface);
    if(0==window){
        return;
    }
}


extern "C"
JNIEXPORT void JNICALL
Java_com_example_myplayerlib_player_MyPlayer__1prepareAsync(JNIEnv *env, jobject instance) {
    player->prepare();
}

extern "C"
JNIEXPORT void JNICALL
Java_com_example_myplayerlib_player_MyPlayer__1start(JNIEnv *env, jobject instance){
    player->play();
}